package com.xixibaby.redis;


import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.xixibaby.core.SuperPO;
import com.xixibaby.core.dict.AdminDict;
import com.xixibaby.core.dict.SuperDictTool;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.lang.reflect.Field;
import java.util.List;

/**
 *
 */
public class Dict implements ApplicationContextAware {

    private static SuperDictTool dictTool;

    public static  <T> String text(SFunction<T,Object> fun, Integer value){
        return dictTool.getText(fun,value);
    }

    public static  <T> String text(Field field, Integer value){
        return dictTool.getText(field,value);
    }

    public static  <T> String key(Field field){
        return dictTool.getKey(field, false);
    }

    public static  <T> String dictMappingKey(Field field){
        return dictTool.getKey(field, true);
    }

    public static <T extends SuperPO> List<AdminDict> list(SFunction<T,Object> fun){
        return dictTool.getList(fun);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        dictTool = applicationContext.getBean(SuperDictTool.class);

    }
}
